package com.ruoyi.hospital.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.hospital.domain.YlMedicalItems;
import com.ruoyi.hospital.service.IYlMedicalItemsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 体检项目信息Controller
 * 
 * @author ruoyi
 * @date 2022-02-16
 */
@RestController
@RequestMapping("/items")
public class YlMedicalItemsController extends BaseController
{
    @Autowired
    private IYlMedicalItemsService ylMedicalItemsService;

    /**
     * 查询体检项目信息列表
     */
    @RequiresPermissions("hospital:items:list")
    @GetMapping("/list")
    public TableDataInfo list(YlMedicalItems ylMedicalItems)
    {
        startPage();
        List<YlMedicalItems> list = ylMedicalItemsService.selectYlMedicalItemsList(ylMedicalItems);
        return getDataTable(list);
    }

    /**
     * 导出体检项目信息列表
     */
    @RequiresPermissions("hospital:items:export")
    @Log(title = "体检项目信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YlMedicalItems ylMedicalItems)
    {
        List<YlMedicalItems> list = ylMedicalItemsService.selectYlMedicalItemsList(ylMedicalItems);
        ExcelUtil<YlMedicalItems> util = new ExcelUtil<YlMedicalItems>(YlMedicalItems.class);
        util.exportExcel(response, list, "体检项目信息数据");
    }

    /**
     * 获取体检项目信息详细信息
     */
    @RequiresPermissions("hospital:items:query")
    @GetMapping(value = "/{medicalItemsId}")
    public AjaxResult getInfo(@PathVariable("medicalItemsId") Long medicalItemsId)
    {
        return AjaxResult.success(ylMedicalItemsService.selectYlMedicalItemsByMedicalItemsId(medicalItemsId));
    }

    /**
     * 新增体检项目信息
     */
    @RequiresPermissions("hospital:items:add")
    @Log(title = "体检项目信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YlMedicalItems ylMedicalItems)
    {
        return toAjax(ylMedicalItemsService.insertYlMedicalItems(ylMedicalItems));
    }

    /**
     * 修改体检项目信息
     */
    @RequiresPermissions("hospital:items:edit")
    @Log(title = "体检项目信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YlMedicalItems ylMedicalItems)
    {
        return toAjax(ylMedicalItemsService.updateYlMedicalItems(ylMedicalItems));
    }

    /**
     * 删除体检项目信息
     */
    @RequiresPermissions("hospital:items:remove")
    @Log(title = "体检项目信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{medicalItemsIds}")
    public AjaxResult remove(@PathVariable Long[] medicalItemsIds)
    {
        return toAjax(ylMedicalItemsService.deleteYlMedicalItemsByMedicalItemsIds(medicalItemsIds));
    }
}
